package com.weixin.xplore.dao.service.impl;

import com.weixin.xplore.controller.domain.request.SysUserPageQueryRequest;
import com.weixin.xplore.dao.common.BaseRepository;
import com.weixin.xplore.dao.entity.SysUser;
import com.weixin.xplore.dao.service.SysUserDaoService;
import com.weixin.xplore.utils.JsonUtil;
import lombok.RequiredArgsConstructor;
import org.anyline.data.param.ConfigStore;
import org.anyline.data.param.init.DefaultConfigStore;
import org.anyline.entity.DataRow;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class SysUserDaoServiceImpl extends BaseRepository<SysUser> implements SysUserDaoService {
    @Override
    public SysUser queryByAccount(String account) {
        ConfigStore configStore = new DefaultConfigStore();
        configStore.eq("account",account);
        return super.selectOne(configStore);
    }

    @Override
    public Boolean save(SysUser sysUser) {
        return super.save(sysUser);
    }

    @Override
    public SysUser queryByInvitation(String invitationCode) {
        ConfigStore configStore = new DefaultConfigStore();
        configStore.eq("extend->'$.invitationCode'",invitationCode);
        return super.selectOne(configStore);
    }

    @Override
    public Boolean updatePopint(String id, Map<String, Object> map) {
        ConfigStore configStore = new DefaultConfigStore();
        configStore.eq("id",id);
        String tableName = getTableName();
        DataRow row = new DataRow();
        row.put("extend", JsonUtil.toStr(map));
       return service.update(tableName, row,configStore)>0;
    }

    @Override
    public Boolean updatePopint(String id, String point) {
        ConfigStore configStore = new DefaultConfigStore();
        configStore.eq("id",id);
        String tableName = getTableName();
        DataRow row = new DataRow();
        row.put("extend", point);
        return  service.update(tableName, row,configStore)>0;
    }

    @Override
    public SysUser queryById(String id) {
        ConfigStore configStore = new DefaultConfigStore();
        configStore.eq("id",id);
        SysUser sysUser = super.selectOne(configStore);
        return sysUser;
    }

    @Override
    public List<SysUser> pageList(SysUserPageQueryRequest queryRequest) {
        return super.page(queryRequest);
    }

}
